package pl.edu.pw.stud.ltrzaska.policy.xml;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.vfs.FileObject;

import pl.edu.pw.stud.ltrzaska.policy.entity.FilesystemObject;
import pl.edu.pw.stud.ltrzaska.policy.entity.PatternObject;

import com.thoughtworks.xstream.converters.Converter;
import com.thoughtworks.xstream.converters.MarshallingContext;
import com.thoughtworks.xstream.converters.UnmarshallingContext;
import com.thoughtworks.xstream.io.HierarchicalStreamReader;
import com.thoughtworks.xstream.io.HierarchicalStreamWriter;

public class PatternObjectConverter extends FileConverter implements Converter {

	@Override
	public boolean canConvert(Class clazz) {
		return clazz.equals(PatternObject.class);
	}	

	@Override
	public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
		PatternObject po = new PatternObject();

		ConverterCommons.preLoopUnmarshal(reader, po);		
		while (reader.hasMoreChildren()) {			
			reader.moveDown();
			ConverterCommons.inLoopUnmarshal(reader, context, po);					
			reader.moveUp();
		}
		return po;
	}

	@Override
	public void marshal(Object obj, HierarchicalStreamWriter hierarchicalstreamwriter,
			MarshallingContext marshallingcontext) {
		// TODO Auto-generated method stub
		
	}
	
	/**
	 * Nie ma odpowiednikow do obiektu stanowiacego wzorzec.
	 * @return
	 */
	public ArrayList<FileObject> findVirtualFsEquivalents() {
		return new ArrayList<FileObject>();
	}
}
